package com.lsx143.wordcount.day3.fight;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Test2_AD {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        env
                .readTextFile("input/AdClickLog.csv")
                .map(new MapFunction<String, Tuple2<String, Long>>() {
                    @Override
                    public Tuple2<String, Long> map(String line) throws Exception {
                        String[] datas = line.split(",");
                        String channel = datas[2] + "," + datas[3];
                        String behavior = datas[1];
                        return new Tuple2<>(channel + "-" + behavior, 1L);
                    }
                })
                .keyBy(t -> t.f0)
                .sum(1)
                .print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}